#include "CTopWidget.h"
#include "ViewHelper.h"

#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QDesktopWidget>
#include <QPaintEvent>
#include <QPainter>
#include <QScreen>
#include <QWindow>

CTopWidget::CTopWidget(QWidget *parent) : CNativeWidget(parent) {
    init();
}

CTopWidget::~CTopWidget() {
}

void CTopWidget::init() {
    m_widget = new QWidget();
    m_widget->setObjectName("content");

    m_layout = new QVBoxLayout(this);
    m_layout->setMargin(0);
    m_layout->setSpacing(0);
    m_layout->addWidget(m_widget);
    setLayout(m_layout);

    // Init
    setResizeMargins(6);
    setBorderWidth(0);
    setResizable(true);
}

QWidget *CTopWidget::widget() const {
    return m_widget;
}

void CTopWidget::setWidget(QWidget *widget) {
    widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    auto *oldItem = m_layout->replaceWidget(m_widget, widget);
    delete oldItem;
    delete m_widget;

    m_widget = widget;
    m_widget->setObjectName("content");
}

void CTopWidget::windowTitleChangeEvent(QEvent *event) {
    Q_UNUSED(event)
}

bool CTopWidget::event(QEvent *event) {
    switch (event->type()) {
    case QEvent::WindowTitleChange: {
        windowTitleChangeEvent(event);
        break;
    }
    default:
        break;
    }
    return CNativeWidget::event(event);
}
